package com.supinfo.youFood.obj;

import java.util.ArrayList;
import java.util.List;

import com.supinfo.food.entities.Customer;

public class copyListPanier {

	static public void copyListCustomer(List<Customer> listone, List<Customer> listtwo,int flag) {
		if (listone == null || listtwo == null)
    		return;
    	for (Customer x : listone)
		{
			Boolean check = false;
			for (Customer b : listtwo)
			{
				if (b.getId().equals(x.getId()))
				{
					for (Candy c : x.getCandy())
					{
						Boolean checkCandy = false;
						for (Candy cb : b.getCandy())
						{
							if (cb.getId().equals(c.getId()))
							{
								cb.setQuantity(cb.getQuantity() + c.getQuantity());
								checkCandy = true;
							}
						}
						if (checkCandy == false)
						{
							Candy candy = new Candy();
							candy.setId(c.getId());
							candy.setIdBase(c.getIdBase());
							candy.setName(c.getName());
							candy.setPrice(c.getPrice());
							candy.setQuantity(c.getQuantity());
							candy.setState(c.getState());
							b.getCandy().add(candy);
						}
					}
					check = true;
				}
			}
			if (check == false)
			{
				Customer cust = new Customer();
				cust.setId(x.getId());
				cust.setIdstr(x.getIdstr());
				cust.setName(x.getName());
				cust.getCandy().addAll(new ArrayList<Candy>(x.getCandy()));
				listtwo.add(cust);
			}
			if (flag == 0)
			x.getCandy().clear();
		}
    	if (flag == 1)
    		listone.clear();
	}
}
